package com.wu.getuglynumber_solution;

/**
 * 丑数
 * @author lynn
 * @date 2020/10/24 - 10:41
 */
public class Solution {
    public static int GetUglyNumber_Solution(int index) {
        if (index < 7) {
            return index;
        }
        int i1 = 0, i2 = 0, i3 = 0;
        int[] arr = new int[index];
        arr[0] = 1;
        for (int i = 1; i < index; i++) {
            arr[i] = Math.min(arr[i1] * 2, Math.min(arr[i2] * 3, arr[i3] * 5));
            if (arr[i] == arr[i1] * 2) {
                i1++;
            }
            if (arr[i] == arr[i2] * 3) {
                i2++;
            }
            if (arr[i] == arr[i3] * 5) {
                i3++;
            }
        }
        return arr[index - 1];
    }

    public static void main(String[] args) {
        int i = GetUglyNumber_Solution(8);
        System.out.println(i);
    }
}